package com.ctrip.demo.leetcode;

public class LeetCode2104 {

    public static void main(String[] args) {
        System.out.println(subArrayRanges(new int[]{1,2,3}));
    }


    public static long subArrayRanges(int[] nums) {

        int n = nums.length, max = 0, min = 0;

        long res = 0;

        for (int i = 0; i < n; i++) {
            max = nums[i];
            min = nums[i];

            for (int j = i + 1; j < n; j++) {
                max = Math.max(max, nums[j]);
                min = Math.min(min, nums[j]);

                res += (max - min);
            }

        }

        return res;

    }

    // 单调栈算法

}
